/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SPasswordInfoConverter.java
 * Created：		2016年7月30日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.statement.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.statement.AQueryByStoreParam;
import com.thor.palmmall.spi.statement.SQueryByStoreParam;

/**
 * @author wolv
 *
 */
public class SQueryByStoreParamConverter
    implements Converter<AQueryByStoreParam, SQueryByStoreParam> {

  public static SQueryByStoreParamConverter getInstance() {
    if (instance == null)
      instance = new SQueryByStoreParamConverter();
    return instance;
  }

  private static SQueryByStoreParamConverter instance;

  private SQueryByStoreParamConverter() {
  }

  @Override
  public SQueryByStoreParam convert(AQueryByStoreParam source) {
    if (source == null)
      return null;

    SQueryByStoreParam target = new SQueryByStoreParam();
    target.setBeginSettle(source.getBeginSettle());
    target.setContracts(new ArrayList<UCN>());
    target.getContracts().addAll(source.getContracts());
    target.setEndSettle(source.getEndSettle());
    target.setKeyword(source.getKeyword());;
    target.setPage(source.getPage());
    target.setPageSize(source.getPageSize());
    target.setStores(new ArrayList<String>());
    target.getStores().addAll(source.getStores());
    target.setUserGroups(new ArrayList<KV>());
    if (source.getUserGroups() != null)
      for (KV sourceUserGroup : source.getUserGroups())
        target.getUserGroups().add(KV.newInstance(sourceUserGroup));
    target.setBizType(UCN.newInstance(source.getBizType()));
    target.setBuilding(UCN.newInstance(source.getBuilding()));
    target.setFloor(UCN.newInstance(source.getFloor()));
    return target;
  }

}
